package mission2.model;

public class LinkedRBinaryTree<E> implements RBinaryTree<E> {
	
	private int size;
	private BTNode<E> root;
	public LinkedRBinaryTree(E value){
		size = 1;
		root = new BTNode<E>(value, null, null, null);
	}

	public LinkedRBinaryTree() {
		root = null;
		size = 0;
	}
	
	public LinkedRBinaryTree(BTNode<E> e){
		size = 1;
		root = e;
	}

	@Override
	public boolean isEmpty() {
		return (root == null);
	}

	@Override
	public int size() {
		return size;	
	}

	@Override
	public Position<E> root() {
		return root;
	}

	@Override
	public boolean isLeaf() {
		BTNode<E> left = (BTNode<E>) root.getLeft();
		BTNode<E> right = (BTNode<E>) root.getRight();
		return (left == null && right == null);
	}

	@Override
	public RBinaryTree<E> leftTree() {
		return new LinkedRBinaryTree<E>((BTNode<E>) root.getLeft());
	}

	@Override
	public RBinaryTree<E> rightTree() {
		return new LinkedRBinaryTree<E>((BTNode<E>) root.getRight());
	}

	@Override
	public void setElement(E o) {
		this.root.setElement(o);
	}

	@Override
	public void setLeft(RBinaryTree<E> tree) {
		this.root.setLeft((BTNode<E>) tree.root());
	}

	@Override
	public void setRight(RBinaryTree<E> tree) {
		this.root.setRight((BTNode<E>) tree.root());
	}

	@Override
	public Iterable<Position<E>> positions() {
		//TODO
		return null;
	}

}
